/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import model.Admin;

/**
 *
 * @author ronaldomartins
 */
public class DaoAdmin extends Dao{

    @Override
    public List listarTodos() {
        List objs = null;
        EntityManager em = getEntityManager();
        objs = em.createQuery("select a from Admin a").getResultList();
        return objs;
    }

    @Override
    public Object buscarPorId(Long id) {
        Object obj = null;
        EntityManager em = getEntityManager();
        obj = em.find(Admin.class, id);
        return obj;
    }
        
    public boolean login(String usuario, String senha){
        boolean retorno = false;
        EntityManager em = getEntityManager();
        retorno = em.createQuery("select a from Admin a where a.usuario = :usuario and a.senha = :senha").
                    setParameter("usuario", usuario).
                    setParameter("senha", senha).
                    getResultList().
                    isEmpty();
        
        return !retorno;
    }    
    
}
